<?php
namespace app\helper\tools;

use think\facade\Cache;

class EasyWechatCache
{
    protected $handler;

    public function __construct()
    {
        if (class_exists('\Predis\Client')) {
            $options = [
                'prefix' => config('cache.prefix'),
                'parameters' => [
                    'password' => config('cache.password'),
                    'database' => config('cache.select'),
                ],
            ];

            $params = [
                'scheme' => 'tcp',
                'host'   => config('cache.host'),
                'port'   => config('cache.port'),
            ];

            $this->handler = new \Predis\Client($params, $options);
        } else {
            $this->handler = Cache::handler();
        }
    }

    public function getHandler()
    {
        return $this->handler;
    }
}
